﻿@using Microsoft.AspNetCore.Components
@inject IdentityAuthenticationStateProvider authStateProvider

<AuthorizeView>
    <Authorized>
        <div class="drawer-profile">
            <MatIconButton Icon="account_circle" Link="/account/profile"></MatIconButton>
            @if (userInfo == null)
            {
                <div class="spinner-border spinner-border-sm" role="status"></div>
            }
            else
            {
                <span class="miniHover"><b><a href="/account/profile">@userInfo.UserName</a></b></span>
            }
        </div>
    </Authorized>
</AuthorizeView>

@code {
    public bool IsLoggedIn = false;
    UserInfoDto userInfo = null;
    [CascadingParameter]
    Task<AuthenticationState> authenticationStateTask { get; set; }

    protected override async Task OnParametersSetAsync()
    {
        userInfo = null;
        var user = (await authenticationStateTask).User;

        if (user.Identity.IsAuthenticated)
        {
            userInfo = await authStateProvider.GetUserInfo();
        }
    }
}